<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>

import { debounce } from "lodash";

const _ = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ {
  constructor(callback) {
    callback = debounce(callback, 100);
    super(callback);
  }
};

// // 窗口化浏览器时报错 ResizeObserver loop completed with undelivered notifications.
// const debounce = (fn, delay) => {
//   let timer = null;
//   return function () {
//     let context = this;
//     let args = arguments;
//     clearTimeout(timer);
//     timer = setTimeout(function () {
//       fn.apply(context, args);

//     }, delay);
//   }
// }

// const _ResizeObserver = window.ResizeObserver;
// window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
//   constructor(callback) {
//     callback = debounce(callback, 16);
//     super(callback);
//   }
// }


// window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
//   constructor(callback) {
//     super(entries => {
//       // 使用requestAnimationFrame来延迟执行回调函数
//       requestAnimationFrame(() => {
//         callback(entries);
//       });
//     });
//   }
// }

// 解决ERROR ResizeObserver loop completed with undelivered notifications.
// 重写ResizeObserver的构造函数，并在其中定义并调用防抖函数
// window.ResizeObserver = class ResizeObserver extends window.ResizeObserver {
//   constructor(callback) {
//     let timer = null;
//     const debouncedCallback = function () {
//       let context = this;
//       let args = arguments;
//       clearTimeout(timer);
//       timer = setTimeout(function () {
//         callback.apply(context, args);
//       }, 100);
//     };
//     super(debouncedCallback);
//   }
// };
export default {
  name: 'App',
  created(){
     // 在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem('store')) {
      this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem('store'))))
    }
    // 在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener('beforeunload', () => {
      sessionStorage.setItem('store', JSON.stringify(this.$store.state))
    })

  
    

  }
}
</script>
<style scoped>
  @import url('./assets/css/table-hover.css');
  @import url('./assets/css/dialog.css');
</style>
